#ifndef SIMULATOR_H_

#define SIMULATOR_H_

#include "common.h"
#include "object.h"
#include "eventqueue.h"

class Timer;

class Simulator : public Object{
	public:
		virtual ~Simulator();

		void scheduleEvent( Event *e, sim_time_t delay );
		void scheduleTimer( Timer *e, sim_time_t delay );
		void scheduleEvent( Event *e );

		sim_time_t clock() const {return time_;}

		void run( void );
		bool isRunning( void ) const;

		static bool create();
		static void destroy();
		static Simulator& instance() {return *instance_;}
	protected:
		Simulator(); 
		bool init();
		void finalize();

		void enqueue( Event *e );
		Event* dequeue( void );

		bool empty( void ) const{
			return event_queue_.empty();
		}

	protected:
		EventQueue event_queue_;
		sim_time_t time_;
		static Simulator *instance_;
};

#endif /* SIMULATOR_H_ */

